package com.allwees.bs.c.module.sys.service.impl;

import com.allwees.bs.c.module.sys.entity.SysParamEntity;
import com.allwees.bs.c.module.sys.repository.SysParamRepository;
import com.allwees.bs.c.module.sys.service.ISysParamService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SysParamServiceImpl implements ISysParamService {

    @Autowired
    private SysParamRepository sysParamRepository;

    @Override
    public String getValue(String name) {
        if (StringUtils.isBlank(name)) {
            return null;
        }
       SysParamEntity entity = sysParamRepository.findByName(name);
        if(entity == null){
            log.warn(">>>>>>>>> 系统参数,name:{}不存在", name);
            return null;
        }
        try{
            return entity.getValue();
        }catch (Exception e){
            log.error(">>>>>>>>>> 获取系统参数,类型转换错误,name:{}", name, e);
        }
        return null;
    }
}
